import java.util.List;

public class Solution120 {
    public int minimumTotal(List<List<Integer>> triangle) {
        List<Integer> list = triangle.get(triangle.size() - 1);
        for (int i = triangle.size() - 2; i >= 0; i--) {
            List<Integer> cur = triangle.get(i);
            for (int j = 0; j < cur.size(); j++) {
                cur.set(j, cur.get(j) + Math.min(list.get(j), list.get(j + 1)));
            }
            list = cur;
        }
        return list.get(0);
    }
}
